<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/30
 * Time: 18:21
 */
require_once(dirname(__FILE__) . '/../../inc/config.inc.php');
require_once(dirname(__FILE__) . '/../../function.php');
IsModelPriv('order');

$page = isset($_GET['page']) ? intval($_GET['page']) : 0;
$size = isset($_GET['limit']) ? intval($_GET['limit']) : 0;
$projectname = isset($_GET['projectname']) ? htmlspecialchars($_GET['projectname']) : "";
$projectname=trim($projectname);
$manageid = isset($_GET['manageid']) ? intval($_GET['manageid']) : 0;
$dtime = isset($_GET['dtime']) ? htmlspecialchars($_GET['dtime']) : "";   //用车人
$dtime=trim($dtime);
$pmid = isset($_GET['pmid']) ? intval($_GET['pmid']) : 0;   //用户的身份
$status= isset($_GET['status']) ? intval($_GET['status']) : -1;   //用户的身份
$start_num = ($page - 1) * $size;



$sql="SELECT *  FROM `#@__project` where is_delete=0  ";

if ($pmid>0) {
    $sql .= "  and pmid='$pmid' ";
}

if ($status>=0) {
    $sql .= "  and jindu='$status' ";
}


if (!empty($projectname)) {
    $sql .= "  and projectname like '%$projectname%'  ";
}
if ($manageid>0) {
    $sql .= "  and FIND_IN_SET($manageid,`manageid`)  ";
}
if ($dtime != "") {
    $time_arr = explode("~", $dtime);
    if (is_array($time_arr) && count($time_arr) == 2) {
        $start_time = strtotime(trim($time_arr[0]));
        $end_time = strtotime(trim($time_arr[1]))+ 3600 * 24 - 1;
        $sql .= " AND post_time>'$start_time' AND post_time<'$end_time' ";

    }

}



$dosql->Execute($sql,8);
$count=$dosql->GetTotalRow(8);
$sql.=" order by id desc  LIMIT $start_num, $size ";
$dosql->Execute($sql);
while ($row = $dosql->GetArray()) {
//    $row['picurl_url'] = "/".$row['picurl'];
    $row['typename'] = getRepairMode($row['apply_device']);
    $row['pm'] = getManage($row['pmid']);
    $row['addtime'] = GetDateTime($row['post_time']);
    $row['times'] =GetDateMk($row['begintime'])."~".GetDateMk($row['endtime']);
    $row_arr['data'][] = $row;
}
if (empty($row_arr['data'])) {
    $row_arr['data'][] = [];
}
$row_arr['code'] = 0;
$row_arr['msg'] = "success";
$row_arr['count'] = $count;
echo json_encode($row_arr);